package com.example.zqm.git72.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.zqm.git72.Adapter.ClubVideoListAdapter;
import com.example.zqm.git72.Adapter.SearchTrainAdapter;
import com.example.zqm.git72.JavaBean.Train;
import com.example.zqm.git72.Model.PhotoModel;
import com.example.zqm.git72.Model.TrainModel;
import com.example.zqm.git72.R;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class SearchTrainActivity extends AppCompatActivity {
    private ImageView send;
    private  EditText in;
    private  RecyclerView recyclerView;
    String name;
    List<Train> train;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_searchtrain);
        recyclerView = (RecyclerView)findViewById(R.id.searching);
        recyclerView.setLayoutManager(new LinearLayoutManager(SearchTrainActivity.this));

        initView();
        initGG();
    }
    public  void  initView(){
        send=(ImageView)findViewById(R.id.send);
        in=(EditText)findViewById(R.id.in);
    }
    public  void initGG(){
        send.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                name =in.getText().toString();
                TrainModel trainModel = new TrainModel();
                Call<List<Train>> call =trainModel.bysearch(name);
                call.enqueue(new Callback<List<Train>>() {
                    @Override
                    public void onResponse(Call<List<Train>> call, Response<List<Train>> response) {
                        train =response.body();
                        recyclerView.setAdapter(new SearchTrainAdapter(SearchTrainActivity.this, train));

                    }

                    @Override
                    public void onFailure(Call<List<Train>> call, Throwable t) {

                    }
                });
            }
        });
    }
}
